/**
 * There are <a href="https://github.com/thinkgem/jeesite">JeeSite</a> code generation
 */
package com.boxin.ims.modules.wechat.service;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.boxin.ims.modules.wechat.dao.WechatSceneFansDao;
import com.boxin.ims.modules.wechat.entity.WechatSceneFans;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.service.BaseService;
import com.zhixun.mobile.common.utils.StringUtils;

/**
 * 扫描渠道二维者Service
 * @author Jakemanse
 * @version 2015-02-05
 */
@Component
@Transactional(readOnly = true)
public class WechatSceneFansService extends BaseService {

	@SuppressWarnings("unused")
	private static Logger logger = LoggerFactory.getLogger(WechatSceneFansService.class);
	
	@Autowired
	private WechatSceneFansDao wechatSceneFansDao;
	
	public WechatSceneFans get(Long id) {
		return wechatSceneFansDao.findOne(id);
	}
	
	public Page<WechatSceneFans> find(Page<WechatSceneFans> page, WechatSceneFans wechatSceneFans) {
		DetachedCriteria dc = wechatSceneFansDao.createDetachedCriteria();
		if (wechatSceneFans.getUser()!=null && wechatSceneFans.getUser().getId()>0){
			dc.add(Restrictions.eq("user.id", wechatSceneFans.getUser().getId()));
		}
		
		
		if (StringUtils.isNotEmpty(wechatSceneFans.getName())){
			dc.add(Restrictions.like("name", "%"+wechatSceneFans.getName()+"%"));
		}
		
		
		if (StringUtils.isNotEmpty(wechatSceneFans.getDay())){
			dc.add(Restrictions.eq("day",  wechatSceneFans.getDay() ));
		}
		
		
		if (StringUtils.isNotEmpty(wechatSceneFans.getType())){
			dc.add(Restrictions.eq("type",  wechatSceneFans.getType() ));
		}
		
		
		dc.addOrder(Order.desc("id"));
		return wechatSceneFansDao.find(page, dc);
	}
	
	@Transactional(readOnly = false)
	public void save(WechatSceneFans wechatSceneFans) {
		wechatSceneFansDao.save(wechatSceneFans);
	}
	
	@Transactional(readOnly = false)
	public void delete(Long id) {
		wechatSceneFansDao.deleteById(id);
	}
	
}
